package com.mwx.baselib.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.BaseRequestOptions;
import com.bumptech.glide.request.RequestOptions;
import com.mwx.baselib.R;
import com.mwx.baselib.net.AppConfig;

public class GlideUtils {


    public static void loadImage(Context context, String url, ImageView imageView) {
        MLog.e("GlideUtils", AppConfig.URL + url + "");
        try {
            Glide.with(context).load(AppConfig.URL + url).into(imageView);
        } catch (Exception e) {
        }
    }

    public static void loadImageRounded10(Context context, String url, ImageView imageView) {
        try {
            Glide.with(context).load(AppConfig.URL + url)
                    .transform(new CenterCrop(), new RoundedCorners(20))
                    .into(imageView);
        } catch (Exception e) {
        }
    }

    public static void loadImageRounded15(Context context, Integer url, ImageView imageView) {
        RequestOptions options = new RequestOptions()
//                .placeholder(R.drawable.loading)
                .bitmapTransform(new RoundedCorners(dip2px(context, 15)));
        Glide.with(context).load(url).apply(options).into(imageView);
    }

    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }


    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

}
